package hk.com.fgoproduction.getdroplets.Service

import android.app.job.JobParameters
import android.app.job.JobService
import android.content.Intent
import android.content.IntentFilter
import hk.com.fgoproduction.getdroplets.BroadcastAndNoti.NotiReceiver
import hk.com.fgoproduction.getdroplets.Lib.Common.ThisApplication
import hk.com.fgoproduction.getdroplets.Lib.Common.ToolInstance.LogInstance
import hk.com.fgoproduction.getdroplets.R

class AutoSyncJob : JobService() {

    // TODO All token verification is based on service and stored in sharedpreferences -> include encryption
    private val showLog = true

    private val SETTING = lazy{ getSharedPreferences(resources.getString(R.string.config), MODE_PRIVATE) }
    private val interval = lazy{ SETTING.value.getLong("interval", 1*60*60*1000) }
    private val TASK = lazy{} //use json to store them and save in local cache

    override fun onStopJob(params: JobParameters?): Boolean {
        LogInstance.log("$this", "Stop job", LogInstance.LogType.INFO, showLog)
        (application as ThisApplication).runOnBg(Runnable{ stopService(Intent(this, FileVerValService::class.java)) })
        return false
    }

    override fun onStartJob(params: JobParameters?): Boolean {
        LogInstance.log("$this", "Start Job", LogInstance.LogType.INFO, showLog)
        (application as ThisApplication).runOnBg(Runnable{ startService(Intent(this, FileVerValService::class.java)) })
        return true
    }

}